package com.asbd.springboot.mapper;

import com.asbd.springboot.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    //新增用户信息
    @Insert("insert into `user` (username, password, name, phone, email, address, avatar) " +
            "values (#{username}, #{password}, #{name}, #{phone}, #{email}, #{address}, #{avatar})")
    void insertUser(User user);

    //根据id修改用户信息
    @Update("update `user` set username = #{username}, password = #{password}, name = #{name}, phone = #{phone}, " +
            "email = #{email}, address = #{address}, avatar = #{avatar} where id = #{id}")
    void updateUser(User user);

    //删除用户信息
    @Delete("delete from `user` where id = #{id}")
    void deleteUser(Integer id);

    //查询全部用户信息
    @Select("select * from `user`")
    List<User> selectAll();
    
    //根据Id查询用户信息
    @Select("select * from `user` where id = #{id};")
    User selectUserById(Integer id);

    //根据用户名查询用户信息
    @Select("select * from `user` where username = #{username};")
    User selectByUsername(String username);
}
